<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/public.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/layui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/header.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/bottom.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/personal_public.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/modify_pswd.css"/>
    <link rel="icon" href="${pageContext.request.contextPath}/layui/images/favicon.ico"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layuimini.css?v=2.0.4.2" media="all"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/themes/default.css" media="all"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all"/>
</head>
<body>
<div class="header">
    <div class="nav">
        <a href="${pageContext.request.contextPath}/renting/index.jsp" class="nav_title">好客租房</a>
        <select class="select">
            <option value="重庆">重庆</option>
            <option value="贵阳">贵阳</option>
            <option value="重庆">重庆</option>
            <option value="贵阳">贵阳</option>
        </select>
        <ul class="nav_ul">
            <li><a href="${pageContext.request.contextPath}/renting/index.jsp">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">轻松找房</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/entry.jsp">房东入驻</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/chat_news.jsp">消息</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/login.jsp" style="color: #2981c8;">登录</a></li>
        </ul>
        <img src="${pageContext.request.contextPath}/renting/img/icon/lianxi-1.png" class="nav_img" style="margin-top: -20px;">
        <p class="nav_phone">
            <span>13301131116</span>
            <span>13301131116</span>
        </p>
    </div>
</div>
<div class="body">
    <div class="content">
        <ul class="left_ul">
            <li class="li_active"><a href="${pageContext.request.contextPath}/renting/pages/onther/personal.jsp"><img src="${pageContext.request.contextPath}/renting/img/xuanzhongtiao.png" >个人资料</a></li>
            <li><a href=""><img src="${pageContext.request.contextPath}/renting/img/xuanzhongtiao.png" >头像</a></li>
        </ul>
        <div class="right_body">
            <div class="right_content">
                <div class="right_title">
                    <p><a href="${pageContext.request.contextPath}/renting/pages/onther/personal.jsp">个人中心</a>><a href="${pageContext.request.contextPath}/renting/pages/onther/modify_pswd.jsp">修改密码</a></p>
                </div>
                <div class="right_main">
                    <form class="my_form" action="">
                        <label>
                            <p>手机号</p>
                            <input readonly value="${drom.phone==null?'您未登陆':drom.phone}" id="userphone" type="text" placeholder="请输入手机号">
                            <span>|</span>
                            <a id="getphonecode">获取验证码</a>
                        </label>
                        <label>
                            <p>验证码</p>
                            <input id="randcode" type="text" placeholder="请输入验证码">
                        </label>
                        <label>
                            <p>新密码</p>
                            <input id="newpassword" type="text" placeholder="请输入新密码">
                        </label>
                        <div class="my_btn">
                            <button type="button" onclick="window.history.back(-1)">取消</button>
                            <input id="commitChage" type="button" value="确认修改" class="btn_sub">
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div style="clear: both;"></div>
    </div>
</div>
<div class="bottom">
    <p>沪公网安备 31011402005354号</p>
</div>
</body>
</html>
<script src="${pageContext.request.contextPath}/renting/js/jQuery-3.4.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/landlord_public.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/header.js"></script>
<script src="../../js/tool.js"></script>
<script type="text/javascript">
    var login=sessionStorage.getItem("login");
    var url="";
    if(login==1){
        url="${pageContext.request.contextPath}/renting/pages/tenant/inspection.jsp";
    }
    if(login==2){
        url="${pageContext.request.contextPath}/renting/pages/landlord/release.jsp";
    }
    judge_login(url,"${pageContext.request.contextPath}/renting/pages/onther/login.jsp");


    //layui全局
    layui.use("layer",function (){
        //获取验证码设置
        $("#getphonecode").click(function (){
            var phonenum = $("#userphone").val().trim();
            var loginphone = ${drom.phone==null?'':drom.phone};
            if(loginphone!=phonenum){
                layer.msg("您未登陆，无法为您提供服务");
            }else{
                $.ajax({
                    url:'${pageContext.request.contextPath}/userInfo/RegistrationVerification',
                    type:'post',
                    async:false,
                    data:{"phoneNumber":"17382243254"},
                    success:function (redata){
                        console.log(redata);
                    }
                })
            }
        })

        //点击检查和请求
        $("#commitChage").click(function (){
            var phonenum = $("#userphone").val().trim();
            var loginphone = ${drom.phone==null?'':drom.phone};
            if(phonenum!=loginphone){
                layer.msg("您未登陆，无法未您提供服务");
            }else{
                if($("#randcode").val().trim().length!=6){
                    layer.msg("验证码的长度是六位数字",{icon:2})
                }else{
                    if($("#newpassword").val().trim().length<6){
                        layer.msg("您的密码长度不够，请重新输入");
                    }else{
                        $.ajax({
                            url:'${pageContext.request.contextPath}/userInfo/changePwd',
                            type:'post',
                            async: false,
                            data:{"pwd":$("#newpassword").val().trim(),"randcode":$("#randcode").val().trim()},
                            dataType:'json',
                            success:function (redata){
                                if(redata.statecode==0){
                                    layer.msg("您的密码已经修改成功，请重新登录",{icon:1},function (){
                                        window.location.href="login.jsp";
                                    })
                                }else{
                                    layer.msg("修改失败，请稍后重试",{icon:2})
                                }
                            },
                            error:function (e){
                                console.log(e);
                            }

                        })
                    }
                }
            }
        })
    })


    //倒计时方法
    function daojishi(classorid,time){
        var object = $(classorid);
        var oldvalue = object.text();
        var oldcolor =object.css("color");
        if(object.attr("timestate")==0){
            return false;
        }
        object.attr("timestate",0);
        object.css("color","#bdbdbd")
        object.text(--time+"秒后重试");
        object.val(--time+"秒后重试");
        object.css("font-size","16px");
        var timer = setInterval(function (){
            --time;
            object.text(time+"秒后重试");
            object.val(time+"秒后重试");
            if(time==0){
                clearInterval(timer);
                object.text(oldvalue);
                object.css("color",oldcolor);
                object.attr("timestate",1);
            }
        },1000)//周期1000毫秒=1秒
        return true;
    }

</script>
